#include "pathNode.h"
#include <stdlib.h>
#include <iostream>

using std::cout;
using std::endl;

//CONSTRUCTORS
Node::Node()
{
    x = -1;
    y = -1;
    walkable = true;
    parent = NULL;
}
Node::Node(int xx, int yy, bool w)
{
    x = xx;
    y = yy;
    walkable = w;
    parent = NULL;
}
Node::~Node()
{
    //Destructor goes here
}


//ACCESSORS
int Node::getx() const
{
    return x;
}

int Node::gety() const
{
    return y;
}

//estimated distance to target
int Node::geth() const
{
    return h;
}

int Node::getg() const
{
    return g;
}

int Node::getf() const
{
    return geth() + getg();
}

bool Node::getw() const
{
    return walkable;
}

Node* Node::getp() const
{
    return parent;
}

//MODIFIERS
int Node::calch(int tarx, int tary)
{//Updates the h variable and returns it for convience
    h = 10*(abs(getx()-tarx) + abs(gety()-tary));
    return h;
}

void Node::setg(int newg)
{
    g = newg;
}

void Node::setp(Node* newp)
{
    parent = newp;
}

void Node::setw(bool neww)
{
    walkable = neww;
}

//OPERATORS
Node& Node::operator=(const Node &nde)
{
    if (*this != nde)
    {
        x=nde.x;
        y=nde.y;
        g=nde.g;
        h=nde.h;
        parent = nde.parent;
    }
    return *this;
}

bool Node::operator==(const Node &nde) const
{
    return ((nde.x == x) && (nde.y == y));
}

bool Node::operator!=(const Node &nde) const
{
    return !(*this == nde);
}

bool Node::operator<(const Node &nde) const
{
    return getf() < nde.getf();
}
bool Node::operator>(const Node &nde) const
{
    return !(getf() < nde.getf()) and !(getf() == nde.getf());
}

void Node::print()
{
    cout << "Node at (" << getx() << "," << gety() << "):" << endl;
    cout << "  " << "f = " << getf() << endl;
    cout << "  " << "g = " << getg() << endl;
    cout << "  " << "h = " << geth() << endl;
    cout << "  " << "Walkable = " << getw() << endl;
    if (getp() != 0)
        cout << "  " << "Parent: (" << getp()->getx() << "," << getp()->getx() << ")" << endl;
}
